package com.ad.pet.app.account;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.ad.pet.App;
import com.ad.pet.DaggerMainActivityCompent;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.common.data.utils.SpUtil;
import com.ad.pet.common.data.utils.ui.DialogUtil;
import com.ad.pet.common.data.utils.ui.ToastUtil;
import com.ad.pet.common.structure.events.RxBus;
import com.ad.pet.common.structure.mvp.BasePresenter;
import com.ad.pet.common.structure.ui.activity.AppToolbarActivity;
import com.ad.pet.constant.Constant;
import com.ad.pet.models.remote.account.AboutUs;
import com.ad.pet.models.remote.account.Account;
import com.ad.pet.models.remote.account.AccountPet;
import com.ad.pet.models.remote.account.pet.PetCateFirst;
import com.ad.pet.models.remote.account.pet.PetColor;
import com.ad.pet.utils.DataCleanManagerUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.just.agentweb.AgentWebConfig;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by SEELE on 2019/5/22.
 */

public class HelpCenterAcitivity extends AppToolbarActivity implements AccountContract.View,AboutUsContract.View{
    @BindView(R.id.tv_about)
    TextView mTvAbout;
    @BindView(R.id.tv_private)
    TextView mTvPrivate;
    @BindView(R.id.tv_terms)
    TextView mTvTerms;
    @BindView(R.id.tv_sitmap)
    TextView mTvSitmap;

    @BindView(R.id.tv_zhuxiao)
    TextView tv_zhuxiao;

    @BindView(R.id.tv_out)
    TextView mTvOut;

    @Inject
    AboutUsPresenter aboutUsPresenter;
    @Inject
    AccountPresenter accountPresenter;

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        mStatusLayoutManager.showContent();
        mToolbar.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        mToolbar.setLeftIcon(R.drawable.whitefanhui);

    }

    @Override
    protected int contentLayout() {
        return R.layout.activity_help_center;
    }

    @Override
    protected void clickRetry(View v) {

    }

    @Override
    protected void initViews() {
    aboutUsPresenter.onCreate(this);
    }

    @Override
    protected void initData() {
        accountPresenter.onCreate(this);
    }

    @Override
    protected void initEvents() {
        mTvAbout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.goResetPwd(mActivity);
            }
        });
        mTvPrivate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AgentWebConfig.clearDiskCache(mActivity);
                DataCleanManagerUtils.clearAllCache(mActivity);
                ToastUtils.showLongToast("清理完成！");

            }
        });
        mTvTerms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Navigation.goAboutUs(mActivity);
            }
        });
        mTvSitmap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        mTvOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                DialogUtil.createDialog(mActivity, "", "是否确认退出登录？", true, "取消", null, "确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        accountPresenter.loginOut(SpUtil.getInstance().getString(Constant.ACCESS_TOKEN));
                    }
                }).show();


            }
        });

        tv_zhuxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                DialogUtil.createDialog(mActivity, "", "是否确认注销账户？", true, "取消", null, "确认", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        aboutUsPresenter.clearAccount();
                    }
                }).show();
            }
        });

    }


    @Override
    public void initInject() {
        DaggerMainActivityCompent.builder().applicationComponent(getApplicationComponent())

                .activityModule(getActivityModule()).build().inject(this);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data == null)
            return;
        switch (requestCode) {
            case MainActivity.REQUEST_GO_MALL:
                setResult(RESULT_OK, data);
                finish();
                break;
            case  100:
                break;
        }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void error(String msg) {

    }

    @Override
    public void error(int code, String msg) {

    }

    @Override
    public void loginOutSuccess() {
        SpUtil.getInstance().putString(Constant.ACCESS_TOKEN, "");
        App.username="";
        App.phone="";
        RxBus.getDefault().post("set_message_number_success");
        ToastUtil.getToastUtil().showShort(getString(R.string.out_success));
        Intent intent = new Intent();
        intent.putExtra("goHome", 1);
        setResult(RESULT_OK, intent);
        finish();
    }

    @Override
    public void getUserInfoSuccess(Account account) {

    }

    @Override
    public void getPetInfoSuccess(AccountPet accountPublic) {

    }

    @Override
    public void uploadHead(String user) {

    }

    @Override
    public void upPetInfoSuccesss() {

    }

    @Override
    public void getPetCategorySuccess(List<PetCateFirst> petCateFirst) {

    }

    @Override
    public void getPetColorSuccess(List<PetColor> petColor) {

    }

    @Override
    public void deletePetSuccess() {

    }

    @Override
    public void upPersonInfoSuccess() {

    }

    @Override
    public void aboutUsSuccess(AboutUs aboutUs) {

    }

    @Override
    public void sendSuggessSuccess() {

    }

    @Override
    public void clearAccountSuccess() {
        SpUtil.getInstance().putString(Constant.ACCESS_TOKEN, "");
        App.username="";
        App.phone="";
        RxBus.getDefault().post("set_message_number_success");
        ToastUtil.getToastUtil().showShort("注销账户成功");
        Intent intent = new Intent();
        intent.putExtra("goHome", 1);
        setResult(RESULT_OK, intent);
        finish();
    }
}
